﻿@model  JewererBasic.PRODUCT
<style type="text/css">
        .table { margin: 4px;  width: 200px;  background-color:#FCFCFC;}
        .head { background-color: #C1D4E6; font-weight: bold; color: #FFF; }
        .webGrid th, .webGrid td { border: 1px solid #C0C0C0; padding: 5px; }
        .altRow { background-color: #E4E9F5; color: #000; }
        .gridHead a:hover {text-decoration:underline;}
        .description { width:auto}
        .selectRow{background-color: #389DF5}
</style>
@using (Html.BeginForm("Index", "Test", FormMethod.Post, new { @id = "WebGridForm", enctype = "multipart/form-data" }))
{    
    if (Model.Drawing != null)
    {
        <img src="@Url.Content(String.Format("~/Content/{0}", Model.Drawing))" width="50" height="50" />
    }
    
    <fieldset>
        <legend>PRODUCTION CARD</legend>
    <table>        
        <tr>
            <td>
                <div>
                    <strong>Item</strong>
                </div>
                @Html.TextBoxFor(model => model.Id,new {style = "width:100px;"})
                @Html.ValidationMessageFor(model => model.Id)
            </td>                    
            <td>
                <div>
                    <strong>Description</strong>
                </div>
                @Html.TextBoxFor(model => model.Description,new {style = "width:150px;"})
                @Html.ValidationMessageFor(model => model.Description)
            </td>                      
            <td>
                <div>
                    <strong>Metal Weight</strong>
                </div>
                @Html.TextBoxFor(model => model.MetalWeight,new {@class ="input" , style = "width:80px;"})
                @Html.ValidationMessageFor(model => model.MetalWeight)
            </td>
            <td>
                <div>
                    <strong>Total Weight</strong>
                </div>
                @Html.TextBoxFor(model => model.TotalWeight,new {@class ="input" , style = "width:80px;"})
                @Html.ValidationMessageFor(model => model.TotalWeight)
            </td>                   
        </tr>                
    </table>           
    <table>       
        <tr>                                  
            <td>
                <div>
                    <strong>Size</strong>
                </div>
                @Html.TextBoxFor(model => model.Size,new {@class ="input" , style = "width:40px;"})
                @Html.ValidationMessageFor(model => model.Size)
            </td>   
            <td>
                <div>
                    <strong>Kind</strong>
                </div>
                @Html.DropDownList("IdKind", string.Empty)
                @Html.ValidationMessageFor(model => model.IdKind)
            </td> 
            <td>
                <div>
                    <strong>Unit</strong>
                </div>
                @Html.DropDownList("IdUnit", String.Empty)
                @Html.ValidationMessageFor(model => model.IdUnit)
            </td>
            <td>
                <div>
                    <strong>Type</strong>
                </div>
                @Html.DropDownList("IdType", String.Empty)
                @Html.ValidationMessageFor(model => model.IdType)
            </td>            
            <td>
                <div>
                    <strong>Gamma</strong>
                </div>
                @Html.DropDownList("IdGamma", String.Empty)
                @Html.ValidationMessageFor(model => model.IdGamma)
            </td>
            <td>
                <input type="file" name="file"/>
            </td>
        </tr>        
    </table>  
    <input type="submit" value="Save" />
    </fieldset>
    
    // casting 
    <fieldset>
        <legend>CASTINGS</legend>
        @if (Model.CASTINGs.Count > 0)
        {
            var grid = new WebGrid(Model.CASTINGs, canPage: true, rowsPerPage: 10);
            grid.Pager(WebGridPagerModes.NextPrevious);
            @grid.GetHtml(tableStyle: "table",
                            headerStyle: "head",
                            alternatingRowStyle: "altRow",
                            selectedRowStyle: "selectRow",
                            columns: grid.Columns(
                                grid.Column("Id", "Item"),
                                grid.Column("Name", "Name"),
                                grid.Column("Decription", "Decription"),
                                grid.Column("Mold", "Mold"),
                                grid.Column("Qty", "Qty"),
                                grid.Column("Weight", "Weight"),
                                grid.Column("UNIT.Name", "Unit"),
                                grid.Column("UNIT.Name", "Type"),
                                grid.Column(columnName: "Edit", format: (item) => @Html.ActionLink("Edit", "EditCasting", "Test", new {id=item.Id}, null)),
                                grid.Column(columnName: "Edit", format: (item) => @Html.ActionLink("Delete", "DeleteCasting", "Test", new { id = item.Id }, null))
            ));      
        }
        <div style="display: none" id="divAddCasting">        
            @Html.Partial("_addProductCasting", new JewererBasic.Models.CastingDummy())
        </div>    
        <input type="button" value="Add Casting" id="ClickToAddCasting" />    
    </fieldset>   
    
    // component 
    <fieldset>
        <legend>COMPONENTS</legend>
        @if(Model.PRODUCT_COMPONENT.Count>0)
        {
            var gridComponent = new WebGrid(Model.PRODUCT_COMPONENT, canPage: true, rowsPerPage: 10);
            gridComponent.Pager(WebGridPagerModes.NextPrevious);
            @gridComponent.GetHtml(tableStyle: "table",
                            headerStyle: "head",
                            alternatingRowStyle: "altRow",
                            selectedRowStyle: "selectRow",
                            columns: gridComponent.Columns(
                                gridComponent.Column("IdComponent", "Item"),
                                gridComponent.Column("COMPONENT.Name", "Name"),
                                gridComponent.Column("COMPONENT.Decription", "Decription"),
                                gridComponent.Column("Qty", "Qty"),
                                gridComponent.Column("Weight", "Weight"),
                                gridComponent.Column("COMPONENT.UNIT.Name", "Unit"),
                                gridComponent.Column("COMPONENT.UNIT.Name", "Type"),
                                gridComponent.Column(columnName: "Edit", format: (item) => Html.ActionLink("Edit", "EditComponent", "Test", new {id=item.IdProduct+","+item.IdComponent}, null)),
                                gridComponent.Column(columnName: "Delete", format: (item) => @Html.ActionLink("Delete", "DeleteComponent", "Test", new {id=item.IdProduct+","+item.IdComponent }, null))
            ));      
        }
        <div style="display: none" id="divAddComponent">        
            @Html.Partial("_addProductComponent", new JewererBasic.Models.Product_Component_Dummy())
        </div>    
        <input type="button" value="Add Component" id="ClickToAddComponent" />
    </fieldset>    
    
    // stone 
    <fieldset>
        <legend>STONES</legend>
        @if (Model.PRODUCT_STONE.Count > 0)
        {
            var gridStone = new WebGrid(Model.PRODUCT_STONE, canPage: true, rowsPerPage: 10);
            gridStone.Pager(WebGridPagerModes.NextPrevious);
            @gridStone.GetHtml(tableStyle: "table",
                            headerStyle: "head",
                            alternatingRowStyle: "altRow",
                            selectedRowStyle: "selectRow",
                            columns: gridStone.Columns(
                                gridStone.Column("IdStone", "Item"),
                                gridStone.Column("STONE.Name", "Name"),
                                gridStone.Column("STONE.Decription", "Decription"),
                                gridStone.Column("Qty", "Qty"),
                                gridStone.Column("Weight", "Weight"),
                                gridStone.Column("STONE.UNIT.Name", "Unit"),
                                gridStone.Column("STONE.UNIT.Name", "Type"),
                                gridStone.Column(columnName: "Edit", format: (item) => Html.ActionLink("Edit", "EditStone", "Test", new {id = item.IdProduct + "," + item.IdStone}, null)),
                                gridStone.Column(columnName: "Delete", format: (item) => Html.ActionLink("Delete", "DeleteStone", "Test", new { id = item.IdProduct + "," + item.IdStone }, null))
            ));      
        }
        <div style="display: none" id="divAddStone">       
            @Html.Partial("_addProductStone", new JewererBasic.Models.Product_Stone_Dummy())
        </div>    
        <input type="button" value="Add Stone" id="ClickToAddStone" />
    </fieldset>    
    
    // process 
    <fieldset>
        <legend>OPERATIONS</legend>
         @if(Model.PRODUCT_PROCESS.Count>0)
         {
            var gridOperation = new WebGrid(Model.PRODUCT_PROCESS, canPage: true, rowsPerPage: 10);
            gridOperation.Pager(WebGridPagerModes.NextPrevious);
            @gridOperation.GetHtml(tableStyle: "table",
                            headerStyle: "head",
                            alternatingRowStyle: "altRow",
                            selectedRowStyle: "selectRow",
                            columns: gridOperation.Columns(
                                gridOperation.Column("ProcessOrder", "ProcessOrder"),
                                gridOperation.Column("PROCESS.Name", "Name"),
                                gridOperation.Column("Time", "Time"),
                                gridOperation.Column("WorkerId", "WorkerId"),                                
                                gridOperation.Column("WeightIN", "WeightIN"),
                                gridOperation.Column("WeightOut", "WeightOut"),
                                gridOperation.Column(header: "DateIn", format: @<div style="width: 200px; text-align: center;">@(((DateTime?)item.DateIN).HasValue ? ((DateTime?)item.DateIN).Value.ToString("MM/dd/yyyy") : "")</div>),
                                gridOperation.Column(header: "DateOut", format: @<div style="width: 200px; text-align: center;">@(((DateTime?)item.DateOut).HasValue ? ((DateTime?)item.DateOut).Value.ToString("MM/dd/yyyy") : "")</div>),
                                gridOperation.Column(columnName: "Edit", format: (item) => Html.ActionLink("Edit", "EditProcess", new { id = item.IdProduct + "," + item.IdProcess })),                                
                                gridOperation.Column(columnName: "Delete", format: (item) => Html.ActionLink("Delete", "DeleteProcess", new { id = item.IdProduct + "," + item.IdProcess }))
            ));      
        }
        <div style="display: none" id="divAddProcess">
            @{JewererBasic.PRODUCT_PROCESS pp = new JewererBasic.PRODUCT_PROCESS();
            }
            @Html.Partial("_addProductProcess", pp)
        </div>    
        <input type="button" value="Add Process" id="ClickToAddProcess" />        
    </fieldset>                                         
    
}   

@section Scripts {
    <script type="text/javascript">
        $(ClickToAddCasting).click(function () {
            $("#divAddCasting").css("display", "block");
        })
    </script>   


    <script type="text/javascript">
        $(ClickToAddStone).click(function () {
            $("#divAddStone").css("display", "block");
        })
    </script> 

    <script type="text/javascript">
        $(ClickToAddProcess).click(function () {
            $("#divAddProcess").css("display", "block");
            $.validator.unobtrusive.parse($('#divAddProcess'));
        })
    </script>   

    <script type="text/javascript">
        $(ClickToAddComponent).click(function () {
            $("#divAddComponent").css("display", "block");
        })
    </script>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $('.input').keydown(function (event) {
                if (jQuery.inArray(event.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
                    // Allow: Ctrl+A
                (event.keyCode == 65 && event.ctrlKey === true) ||
                    // Allow: home, end, left, right
                (event.keyCode >= 35 && event.keyCode <= 40)) {

                    return;
                }
                else {
                    // Ensure that it is a number and stop the keypress
                    if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
                        event.preventDefault();
                    }
                    else {
                        var $focused = $(':focus');
                        if ($focused.val().length >= 10) {
                            $focused.keydown(function (event) {
                                event.preventDefault();
                            })
                        }
                    }
                }
            });
        });
    </script>
}

